//package com.sztz.handle;
//
//import cn.hutool.json.JSONUtil;
//import com.sztz.result.BaseResult;
//import com.sztz.result.ResultEnum;
//import com.sztz.utils.CommUtils;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.security.authentication.BadCredentialsException;
//import org.springframework.security.core.AuthenticationException;
//import org.springframework.security.web.authentication.AuthenticationFailureHandler;
//import org.springframework.stereotype.Component;
//
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServletResponse;
//
///**
// * 自定义登录认证失败处理器
// * @author yzy
// * @date 2023/3/15 14:59
// */
//@Component
//@Slf4j
//public class MyAuthenticationFailureHandler implements AuthenticationFailureHandler {
//    @Override
//    public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response, AuthenticationException exception)  {
//        log.info("用户认证未通过 MyAuthenticationFailureHandler: {}",exception.getMessage());
//        //BadCredentialsException异常就提示 : 用户名密码错误，其它异常就提示 : 登录失败
//        ResultEnum resultEnum = exception instanceof BadCredentialsException ? ResultEnum.LOGIN_AUTHENTICATION_FAIL:ResultEnum.LOGIN_FAIL;
//        CommUtils.responseJsonMessage(response, JSONUtil.toJsonStr(BaseResult.fail(resultEnum)));
//    }
//}
